package business;
import java.util.*;

import persistence.*;

/*
 * Singleton Class
 */
public class HallBook 
{
	//member variables
	private static HallBook Instance;
	private ArrayList<Hall> Halls;
	
	/*
	 * private Constructor because Singleton Class
	 */
	private HallBook()
	{
		Halls = new ArrayList<Hall>(30);
		LoadFromStorage();
	}
	
	/*
	 * Singleton Class Method. Returns Instance of Class.
	 */
	public static HallBook GetInstance()
	{
		if(Instance==null)
		{
			Instance = new HallBook();
			return Instance;
		}
		
		else
		{
			return Instance;
		}
	}
	
	//methods
	public Hall Find(int ID)
	{
		for(Hall hall : Halls)
		{
			if(hall.getID() == ID)
			{
				return hall;
			}
		}
		return null;
	}
	
	private void LoadFromStorage()
	{
		ArrayList<HallFascade> temp;
		temp = HallTDG.FindAll();
		Hall.setID_Counter(HallFascade.getID_Counter()); //set the static value for counters
		
		for(HallFascade HF : temp)
		{
			Halls.add(new Hall(HF.getID(),HF.getRoomNumber(),HF.getSeatCapacity()));
		}
		

	}

}
